export const navigateclicklistener = (e: Event) => {
    if (!(e instanceof MouseEvent)) {
        return;
    }
    let target = e.target;
    // console.log(e);

    // if (
    //     !(e.target instanceof HTMLAnchorElement) &&
    //     e instanceof MouseEvent
    // ) {
    //     //@ts-ignore
    //     const evnetpath: Element[] = e.path as Element[];
    //     target =
    //         evnetpath.find(
    //             (ele) => ele instanceof HTMLAnchorElement
    //         ) || target;
    // }
    if (target && target instanceof HTMLAnchorElement) {
        if (
            target.classList.contains("navigate") &&
            (!target.target || target.target !== "_blank") &&
            target.href &&
            target.origin === location.origin
        ) {
            // console.log(target);
            history.pushState(null, "", target.href);
            window.dispatchEvent(new Event("popstate"));
            window.dispatchEvent(new Event("hashchange"));
            e.preventDefault();
        }
    }
};
